<template>
  <div>
    <el-tabs type="border-card">
    <el-tab-pane label="基本信息">
      <el-form ref="employeesRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="empEntrydate">
          <el-date-picker clearable
            v-model="form.empEntrydate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="姓名" prop="empName">
          <el-input v-model="form.empName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="图片" prop="empPicture">
          <image-upload v-model="form.empPicture"/>
        </el-form-item>
        <el-form-item label="年龄" prop="empAge">
          <el-input v-model="form.empAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="薪资" prop="empSalary">
          <el-input v-model="form.empSalary" placeholder="请输入薪资" />
        </el-form-item>
        <el-form-item label="学历" prop="empEducation">
          <el-select v-model="form.empEducation" placeholder="请选择学历">
            <el-option
              v-for="dict in xl"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岗位" prop="empPosition">
          <el-select v-model="form.empPosition" placeholder="请选择岗位">
            <el-option
              v-for="dict in gw"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="民族" prop="empNation">
          <el-select v-model="form.empNation" placeholder="请选择民族">
            <el-option
              v-for="dict in mz"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="个人id" prop="empId">
          <el-input v-model="form.empId" placeholder="请输入个人id" />
        </el-form-item>
        <el-divider content-position="center">就业信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="Plus" @click="handleAddSakuraExp">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="Delete" @click="handleDeleteSakuraExp">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="sakuraExpList" :row-class-name="rowSakuraExpIndex" @selection-change="handleSakuraExpSelectionChange" ref="sakuraExp">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="就业时长" prop="experienceTime" width="240">
            <template #default="scope">
              <el-date-picker clearable
                v-model="scope.row.experienceTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择就业时长">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="就业情况" prop="experienceCondition" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.experienceCondition" placeholder="请输入就业情况" />
            </template>
          </el-table-column>
          <el-table-column label="就业材料" prop="experienceFiles" width="150">
            <!-- <el-form-item label="就业材料" prop="experienceFiles"> -->
          <file-upload v-model="form.experienceFiles"/>
        <!-- </el-form-item> -->
          </el-table-column>
        </el-table>
      </el-form>
      
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      
  </el-tab-pane>
    <el-tab-pane label="就业经历"><exp></exp></el-tab-pane>
    <el-tab-pane label="个人荣誉"><honor></honor></el-tab-pane>
    <el-tab-pane label="个人中心"><personal></personal></el-tab-pane>
  </el-tabs>
    
  </div>
</template>
<script setup>
import { listEmployees, getEmployees, delEmployees, addEmployees, updateEmployees } from "@/api/demo/employees";
import exp from "@/views/demo/exp/index.vue";

components: { exp };

const { proxy } = getCurrentInstance();
const { mz, gw, xl } = proxy.useDict('mz', 'gw', 'xl');

const employeesList = ref([]);
const sakuraExpList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const checkedSakuraExp = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    empEntrydate: null,
    empName: null,
    empPicture: null,
    empAge: null,
    empSalary: null,
    empEducation: null,
    empPosition: null,
    empNation: null,
    empId: null
  },
  rules: {
    empEntrydate: [
      { required: true, message: "日期不能为空", trigger: "blur" }
    ],
    empName: [
      { required: true, message: "姓名不能为空", trigger: "blur" }
    ],
    empEducation: [
      { required: true, message: "学历不能为空", trigger: "change" }
    ],
    empPosition: [
      { required: true, message: "岗位不能为空", trigger: "change" }
    ],
    empNation: [
      { required: true, message: "民族不能为空", trigger: "change" }
    ],
    empId: [
      { required: true, message: "个人id不能为空", trigger: "blur" }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);


/** ${subTable.functionName}添加按钮操作 */
function handleAddSakuraExp() {
  let obj = {};
  obj.experienceTime = "";
  obj.experienceCondition = "";
  obj.experienceFiles = "";
  sakuraExpList.value.push(obj);
}

/** ${subTable.functionName}删除按钮操作 */
function handleDeleteSakuraExp() {
  if (checkedSakuraExp.value.length == 0) {
    proxy.$modal.msgError("请先选择要删除的${subTable.functionName}数据");
  } else {
    const sakuraExps = sakuraExpList.value;
    const checkedSakuraExps = checkedSakuraExp.value;
    sakuraExpList.value = sakuraExps.filter(function(item) {
      return checkedSakuraExps.indexOf(item.index) == -1
    });
  }
}

function cancel() {
  open.value = false;
  reset();
}

function handleSakuraExpSelectionChange(selection) {
  checkedSakuraExp.value = selection.map(item => item.index)
}

/** ${subTable.functionName}序号 */
function rowSakuraExpIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    empEntrydate: null,
    empName: null,
    empPicture: null,
    empAge: null,
    empSalary: null,
    empEducation: null,
    empPosition: null,
    empNation: null,
    empId: null
  };
  sakuraExpList.value = [];
  proxy.resetForm("employeesRef");
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["employeesRef"].validate(valid => {
    if (valid) {
      form.value.sakuraExpList = sakuraExpList.value;
      console.log(form.value);
      console.log(sakuraExpList.value);
        addEmployees(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      
    }
  });
}


</script>
<style>
</style>
